import { createRouter, createWebHistory } from 'vue-router';
import LoginPage from '../components/LoginPage.vue';
import RegisterPage from '../components/RegisterPage.vue';
import QuestionnairePage from '../components/QuestionnairePage.vue';
import IndexPage from '../components/IndexPage.vue';
import ProfilePage from '../components/ProfilePage.vue';
import AppointmentsPage from '../components/AppointmentsPage.vue';
import MessagesPage from '../components/MessagesPage.vue';

const routes = [
  {
    path: '/',
    redirect: '/index',  // 默认跳转到注册页面
  },
  {
    path: '/index',
    name: 'IndexPage',
    component: IndexPage,
    meta:{title:'心理预约系统'}
  },
  {
    path: '/login',
    name: 'LoginPage',
    component: LoginPage,
    meta:{title:'用户登陆'}
  },
  {
    path: '/register',
    name: 'RegisterPage',
    component: RegisterPage,
    meta:{title:'用户注册'}
  },
  {
    path: '/questionnaire',
    name: 'QuestionnairePage',
    component: QuestionnairePage,
    meta:{title:'问卷填写'}
  },
  {
    path: '/profile',
    name: 'ProfilePage',
    component: ProfilePage,
    meta:{title:'个人资料'}
  },
  {
    path: '/appointments',
    name: 'AppointmentsPage',
    component: AppointmentsPage,
    meta:{title:'我的预约'}
  },
  {
    path: '/messages',
    name: 'MessagesPage',
    component: MessagesPage,
    meta:{title:'我的消息'}
  },
];

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
});

//设置页面路由标题自动跟随
router.beforeEach((to,from,next)=>{
    if(to.meta.title){
        document.title=to.meta.title;
    }
    next();
})

export default router;
